"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global globalRootUrl, Form, globalTranslate */

/**
 * Process common module settings.
 * @module pbxExtensionModuleModify
 */
var pbxExtensionModuleModify = {
  /**
   * jQuery object for the form.
   * @type {jQuery}
   */
  $formObj: $('#pbx-extension-modify-form'),

  /**
   * jQuery object for the back button.
   * @type {jQuery}
   */
  $backButton: $('#back-to-list-button'),

  /**
   * jQuery object for the dropdown menu.
   * @type {jQuery}
   */
  $dropdownMenuGroups: $('#menu-group'),

  /**
   * Validation rules for the form fields before submission.
   * @type {object}
   */
  validateRules: {
    name: {
      identifier: 'caption',
      rules: [{
        type: 'empty',
        prompt: globalTranslate.ext_ValidateCaptionEmpty
      }]
    }
  },

  /**
   * Initializes the module.
   */
  initialize: function initialize() {
    pbxExtensionModuleModify.$dropdownMenuGroups.dropdown();
    pbxExtensionModuleModify.initializeForm();
  },

  /**
   * Callback function to be called before the form is sent
   * @param {Object} settings - The current settings of the form
   * @returns {Object} - The updated settings of the form
   */
  cbBeforeSendForm: function cbBeforeSendForm(settings) {
    var result = settings;
    result.data = pbxExtensionModuleModify.$formObj.form('get values');
    return result;
  },

  /**
   * Callback function to be called after the form has been sent.
   * @param {Object} response - The response from the server after the form is sent
   */
  cbAfterSendForm: function cbAfterSendForm(response) {
    window.location = window.location.href;
  },

  /**
   * Initialize the form with custom settings
   */
  initializeForm: function initializeForm() {
    Form.$formObj = pbxExtensionModuleModify.$formObj;
    Form.url = "".concat(globalRootUrl, "pbx-extension-modules/save"); // Form submission URL

    Form.validateRules = pbxExtensionModuleModify.validateRules; // Form validation rules

    Form.cbBeforeSendForm = pbxExtensionModuleModify.cbBeforeSendForm; // Callback before form is sent

    Form.cbAfterSendForm = pbxExtensionModuleModify.cbAfterSendForm; // Callback after form is sent

    Form.initialize();
  }
}; // When the document is ready, initialize the external module management form.

$(document).ready(function () {
  pbxExtensionModuleModify.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9QYnhFeHRlbnNpb25Nb2R1bGVzL3BieC1leHRlbnNpb24tbW9kdWxlLW1vZGlmeS5qcyJdLCJuYW1lcyI6WyJwYnhFeHRlbnNpb25Nb2R1bGVNb2RpZnkiLCIkZm9ybU9iaiIsIiQiLCIkYmFja0J1dHRvbiIsIiRkcm9wZG93bk1lbnVHcm91cHMiLCJ2YWxpZGF0ZVJ1bGVzIiwibmFtZSIsImlkZW50aWZpZXIiLCJydWxlcyIsInR5cGUiLCJwcm9tcHQiLCJnbG9iYWxUcmFuc2xhdGUiLCJleHRfVmFsaWRhdGVDYXB0aW9uRW1wdHkiLCJpbml0aWFsaXplIiwiZHJvcGRvd24iLCJpbml0aWFsaXplRm9ybSIsImNiQmVmb3JlU2VuZEZvcm0iLCJzZXR0aW5ncyIsInJlc3VsdCIsImRhdGEiLCJmb3JtIiwiY2JBZnRlclNlbmRGb3JtIiwicmVzcG9uc2UiLCJ3aW5kb3ciLCJsb2NhdGlvbiIsImhyZWYiLCJGb3JtIiwidXJsIiwiZ2xvYmFsUm9vdFVybCIsImRvY3VtZW50IiwicmVhZHkiXSwibWFwcGluZ3MiOiI7O0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFFQTs7QUFFQTtBQ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